package jspx.example.dao.impl;


import com.github.jspxnet.json.JSONObject;
import com.github.jspxnet.sioc.annotation.Bean;
import com.github.jspxnet.sioc.annotation.Init;
import com.github.jspxnet.sioc.annotation.Ref;
import com.github.jspxnet.sober.SoberFactory;
import com.github.jspxnet.sober.annotation.SqlMap;
import com.github.jspxnet.sober.enums.QueryModelEnumType;
import com.github.jspxnet.sober.jdbc.JdbcOperations;
import jspx.example.conf.Persion;
import jspx.example.dao.IocDemoDAO;
import jspx.example.env.DemoIoc;
import jspx.example.table.Employee;

import java.util.List;
import java.util.Map;

/**
 * 特殊DAO例子
 */
@Bean(namespace = DemoIoc.namespace)
public class IocDemoDAOImpl  extends JdbcOperations implements IocDemoDAO {

    @Init
    public void initRun()
    {
        System.out.println("---------init run");
    }

    @Override
    public String getPersionJson(Persion persion)
    {
        JSONObject json = new JSONObject(persion);
        return json.toString(4);
    }

    @Ref(name = "jspxSoberFactory" ,namespace = DemoIoc.namespace)
    @Override
    public void setSoberFactory(SoberFactory soberFactory) {
        super.setSoberFactory(soberFactory);
    }

    public JSONObject getPersionJsonObject(Persion persion)
    {
        return  new JSONObject(persion);
    }

    @Override
    @SqlMap
    public List<Employee> getList(Map<String, Object> valueMap, int currentPage, int count,Class<?> cls) {
        valueMap.put("employeeTable", getTableName(Employee.class));
        return null;
    }

    @Override
    @SqlMap(intercept = "jspx.example.interceptor.db.DemoInterceptor")
    public List<Employee> getEmployeeList(Map<String, Object> valueMap, int currentPage, int count) {
        valueMap.put("employeeTable", getTableName(Employee.class));
        return null;
    }

    @Override
    @SqlMap(id="jspx.example.dao.IocDemoDAO.getEmployeeList",intercept = "jspx.example.interceptor.db.IntDemoInterceptor",mode = QueryModelEnumType.COUNT)
    public long getEmployeeListCount(Map<String, Object> valueMap) {
        valueMap.put("employeeTable", getTableName(Employee.class));
        return 0;
    }

    @Override
    @SqlMap(mode = QueryModelEnumType.SINGLE)
    public long getEmployeeListSing(Map<String, Object> valueMap) {
        valueMap.put("employeeTable", getTableName(Employee.class));
        return 0;
    }

    @Override
    @SqlMap(intercept = "jspx.example.interceptor.db.IntDemoInterceptor",mode = QueryModelEnumType.SINGLE)
    public long getEmployeeListSing2(Map<String, Object> valueMap) {
        valueMap.put("employeeTable", getTableName(Employee.class));
        return 0;
    }

}
